<?php

ini_set('display_errors', 'on');
error_reporting(E_ALL ^ E_NOTICE);

/**
 * Clix Framework Advanced Example
 * 
 * @author: Petr Kratina <petr.kratina@gmail.com>
 */  

require_once '../../Clix.php';

class Application extends Clix
{
    public function bookAction()
    {
        if ((!empty($_POST['nick']))and(!empty($_POST['message']))) {
            $sql = "INSERT INTO book (`nick`, `message`, `added`)
                              VALUES ({$this->db->quote($_POST['nick'])},
                                      {$this->db->quote($_POST['message'])},
                                      CURRENT_TIMESTAMP)";
            $this->db->query($sql);
        }
    
        $sql = "SELECT * FROM book ORDER BY added DESC";
        $this->view->book = $this->db->fetchAll($sql);
    }
    
    public function contactsAction()
    {
        if ($this->_getParam(1)=='form') {
            $this->actionTemplate = 'contacts/form.phtml';
            if ((!empty($_POST['email']))and(!empty($_POST['body']))) {
                $this->view->sent = true;
                mail('clix@openinbox.org', 'Message from web', strip_tags($_POST['body']), "Content-type: text/plain; charset=UTF-8\nFrom: ".strip_tags($_POST['email']));
            }
        }
    }
}

new Application('app.ini');
